package com.ruoyi.project.poem.teacoinpackage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MoneyUtil;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.poem.teacoinpackage.domain.TeacoinPackage;
import com.ruoyi.project.poem.teacoinpackage.mapper.TeacoinPackageMapper;
import com.ruoyi.project.poem.teacoinpackage.service.ITeacoinPackageService;

/**
 * 茶币充值套餐Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-04-28
 */
@Service
@DataSource(DataSourceType.ACCOUNT)
public class TeacoinPackageServiceImpl implements ITeacoinPackageService {
	@Autowired
	private TeacoinPackageMapper teacoinPackageMapper;

	/**
	 * 查询茶币充值套餐
	 * 
	 * @param id 茶币充值套餐ID
	 * @return 茶币充值套餐
	 */
	@Override
	public TeacoinPackage selectTeacoinPackageById(Long id) {
		return teacoinPackageMapper.selectTeacoinPackageById(id);
	}

	/**
	 * 查询茶币充值套餐列表
	 * 
	 * @param teacoinPackage 茶币充值套餐
	 * @return 茶币充值套餐
	 */
	@Override
	public List<TeacoinPackage> selectTeacoinPackageList(TeacoinPackage teacoinPackage) {
		List<TeacoinPackage> list = teacoinPackageMapper.selectTeacoinPackageList(teacoinPackage);
		list.forEach(item -> {
			item.setYuan(MoneyUtil.fee2yuan(item.getFee()).toString());
			item.setDiscountYuan(MoneyUtil.fee2yuan(item.getDiscountFee()).toString());
		});
		return list;
	}

	/**
	 * 新增茶币充值套餐
	 * 
	 * @param teacoinPackage 茶币充值套餐
	 * @return 结果
	 */
	@Override
	public int insertTeacoinPackage(TeacoinPackage teacoinPackage) {
		teacoinPackage.setCreateTime(DateUtils.getNowDate());
		teacoinPackage.setCreateBy(ShiroUtils.getLoginName());
		return teacoinPackageMapper.insertTeacoinPackage(teacoinPackage);
	}

	/**
	 * 修改茶币充值套餐
	 * 
	 * @param teacoinPackage 茶币充值套餐
	 * @return 结果
	 */
	@Override
	public int updateTeacoinPackage(TeacoinPackage teacoinPackage) {
		teacoinPackage.setUpdateTime(DateUtils.getNowDate());
		teacoinPackage.setUpdateBy(ShiroUtils.getLoginName());
		return teacoinPackageMapper.updateTeacoinPackage(teacoinPackage);
	}

	/**
	 * 删除茶币充值套餐对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteTeacoinPackageByIds(String ids) {
		return teacoinPackageMapper.deleteTeacoinPackageByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除茶币充值套餐信息
	 * 
	 * @param id 茶币充值套餐ID
	 * @return 结果
	 */
	@Override
	public int deleteTeacoinPackageById(Long id) {
		return teacoinPackageMapper.deleteTeacoinPackageById(id);
	}
}
